using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Pool;

delegate void testDel(int x);

public class ActiveObjectCollectionEvent : MonoBehaviour
{
    [Header("this is animation prefab Component")]
    public List<GameObject> collectionObject;

    ObjectPool<GameObject> objectList;

    public void init()
    {
        objectList = new ObjectPool<GameObject>(onObjectCreateEvent, onObjectGetEvent, onObjectEndEvent, onObjectDestroyEvent,
            true,100,1000);
    }

    public GameObject get(int index)
    {
        return collectionObject[index];
    }

    public int size()
    {
        return collectionObject.Count;
    }

    private void onObjectDestroyEvent(GameObject obj)
    {
        Destroy(obj);
    }

    private void onObjectEndEvent(GameObject obj)
    {
        obj.SetActive(false);
    }

    private void onObjectGetEvent(GameObject obj)
    {
        obj.SetActive(true);
    }

    private GameObject onObjectCreateEvent()
    {
        GameObject obj = Instantiate(collectionObject?[0], transform);
        return obj;
    }


    public void testDel()
    {
        HelloWorld hw = new HelloWorld();
        testDel t = hw.sayNumber;
        t(42);
    }

}

class HelloWorld
{
    public void sayNumber(int num)
    {
        Debug.Log("this is Number:" + num);
    }
}